<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants,org.apache.struts.util.LabelValueBean" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/dieBankReport.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<%

    String productId     = request.getParameter("product");
    String partNumber    = request.getParameter("partnumber");

    if( partNumber == null || ( partNumber != null && partNumber.trim().length() == 0 ) )
    {
        partNumber = "0";
    }
    if( productId == null || ( productId != null && productId.trim().length() == 0 ) )
    {
        productId = "0";
    }
%>

<html>
    <HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
        <META http-equiv=Content-Type content="text/html; charset=windows-1252">
        <LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
    </HEAD>
    <BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0" >
    <script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
    <SCRIPT language="JavaScript">

    var dateElement = "";
    function openCalendar(dateValue)
    {
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
    }
    function assignDate(passedValue)
    {
    dateElement.value=passedValue;
    window.focus();
    }

    function validateFromAndToDates()
    {
        var formdoc = document.sortLotReport;
        errMsg = '';

        var pa	= document.getElementById("errors")

        if(chkDate(formdoc.datefrom.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.datefrom.focus();
            return false;
        }

        if(chkDate(formdoc.dateto.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.dateto.focus();
            return false;
        }

        if(formdoc.datefrom.value!='' && formdoc.dateto.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.datefrom.value),formatDateAsMMDDYYYY(formdoc.dateto.value)))
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                formdoc.dateto.focus();
                return false;
            }
        }
        return true;
    }

    function loadPartNumbers()
    {
        var baseProductId = document.sortLotReport.product.value;
        if ( document.sortLotReport.product.value == 0 )
        {
            document.sortLotReport.action ="<%=chipTracContext%>/dieBankReport.do?reportType=sortBinClosedLotReport";
            document.sortLotReport.submit();
            return;
        }
        document.sortLotReport.action ="<%=chipTracContext%>/dieBankReport.do?reportType=sortBinClosedLotReport&action=loadPartNumbers&baseProductId="+ baseProductId;
        document.sortLotReport.submit();
    }

    function submitPage()
    {

		var d = new Date();
		var day = d.getDate();
		var month = d.getMonth()+1;
		var year = d.getFullYear();
		var hour = d.getHours();
		var min = d.getMinutes();
		var sec = d.getSeconds();

		var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

		var reporttype        = "";

        var success;
        success = true;
        success = validateFromAndToDates();
        if(success == false)
        {
           return false;
        }

        if (document.sortLotReport.partnumber.value == '')
        {
            document.sortLotReport.prompt0.value='0';
        }
		else
        {
            document.sortLotReport.prompt0.value = document.sortLotReport.partnumber.value;
        }

		if (document.sortLotReport.product.value == '')
        {
            document.sortLotReport.prompt1.value='0';
        }
		else
        {
            document.sortLotReport.prompt1.value = document.sortLotReport.product.value;
        }

        if (document.sortLotReport.datefrom.value == '')
        {
            document.sortLotReport.prompt2.value='0';
        }
        else
        {
            document.sortLotReport.prompt2.value = document.sortLotReport.datefrom.value;
        }
        if (document.sortLotReport.dateto.value == '')
        {
            document.sortLotReport.prompt3.value='0';
        }
        else
        {
            document.sortLotReport.prompt3.value = document.sortLotReport.dateto.value;
        }
		document.sortLotReport.prompt4.value ='';
		document.sortLotReport.prompt5.value ='';
		document.sortLotReport.prompt6.value =defaultPrompt;
		document.sortLotReport.prompt7.value='';
		document.sortLotReport.prompt8.value ='';
		document.sortLotReport.prompt9.value ='';
		document.sortLotReport.prompt10.value ='';

		document.sortLotReport.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/Sort_Bin_Closed_Lot_Report.rpt";

    }

    </script>
    <!-- Top Header Start-->
    <%@ include file="/jsp/includes/header.jsp" %>
    <!-- Top Header End-->
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
      <TBODY >
      <TR>
        <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

        <!-- Side Navigation start -->
        <%@ include file="/jsp/operations/reports_side_menu.jsp" %></TD>
        <!-- end of the side navigations -->

        <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
        <!-- from here your body starts -->
        <form name="sortLotReport" method= "post">
        <input type="hidden" name="prompt0">
        <input type="hidden" name="prompt1">
        <input type="hidden" name="prompt2">
        <input type="hidden" name="prompt3">
        <input type="hidden" name="prompt4">
        <input type="hidden" name="prompt5">
        <input type="hidden" name="prompt6">
        <input type="hidden" name="prompt7">
        <input type="hidden" name="prompt8">
        <input type="hidden" name="prompt9">
        <input type="hidden" name="prompt10">

        <TABLE width='75%' align=center cellpadding='3' cellspacing='2' border='0' bordercolor='black'>
                <TR><Td colspan='4' class="NArialW" align=center>Sort Closed Lot Report</td></tr>
                <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                <tr><td colspan='4' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></td></tr>
                <TR><TD colspan='4' id="chiptracErrors"><chiptrack:errors styleClass="NArialL"/></TD></TR>
                <TR><TD colspan='4'><chiptrack:info styleClass="NArialL"/></TD></TR>
                <tr>
                    <td width="15%" class="NArialL">Base Product</td>
                    <td width="20%" class="NArialL">
                        <select size="1" name="product" class="txfield" onchange="loadPartNumbers()">
                            <option value="0">All Products</option>
                                <logic:iterate id="baseProductSelectList"  name="baseProductList" >
                                    <logic:equal name="baseProductSelectList" property="value" value="<%=productId%>"><option value="<bean:write name="baseProductSelectList" property="value"/>" selected><bean:write name="baseProductSelectList" property="label"/></option></logic:equal>
                                    <logic:notEqual name="baseProductSelectList" property="value" value="<%=productId%>"><option value="<bean:write name="baseProductSelectList" property="value"/>"><bean:write name="baseProductSelectList" property="label"/></option></logic:notEqual>
				                </logic:iterate>
                         </select>
                    </td>
                    <td width="15%" class="NArialL">Part Number</td>
                    <td width="20%" class="NArialL">
                        <select size="1" name="partnumber" class="txfield">
                            <option value="0">All Part Numbers</option>
                                <logic:iterate id="partNumberSelectList" name="partNumberList" >
                                    <logic:equal name="partNumberSelectList" property="value" value="<%=partNumber %>"><option value="<bean:write name="partNumberSelectList" property="value"/>" selected><bean:write name="partNumberSelectList" property="label"/></option></logic:equal>
                                    <logic:notEqual name="partNumberSelectList" property="value" value="<%=partNumber%>"><option value="<bean:write name="partNumberSelectList" property="value"/>"><bean:write name="partNumberSelectList" property="label"/></option></logic:notEqual>
				                </logic:iterate>
                        </select>
                    </td>

                </tr>
                <tr><td colspan="4" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

                <tr>
                    <td width="15%" class="NArialL">From-Date</td>
                    <td width="20%" class="NArialL">
                        <input type="text" name="datefrom" size="15" class="txfield">&nbsp;
                        <a href="javascript:openCalendar(document.sortLotReport.datefrom)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                    </td>
                    <td width="15%" class="NArialL">To-Date</td>
                    <td width="20%" class="NArialL">
                        <input type="text" name="dateto" size="15" class="txfield">&nbsp;
                        <a href="javascript:openCalendar(document.sortLotReport.dateto)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                    </td>
                </tr>
                <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
                <tr>
                    <td width="70%" colspan=5 align="center">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="image" onClick="javascript:return submitPage();"  border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Report';return true"onmouseout="window.status='';return true"title="Click here to Generate Report">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:document.sortLotReport.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
                    </td>
                </tr>
     </table>
     </form>
     <!-- till here -->
     <BR><BR>
     </TD><TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
     </TABLE>
     <!-- Footer starts here -->
     <%@ include file="/jsp/includes/footer.jsp" %>
     <!-- footer end here -->
    </body>
</html>

